<?php
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past
include('../class.base.php');
if (isset($_GET["tabel"])) {
	$tabel = htmlspecialchars($_GET["tabel"], ENT_QUOTES);
	$systemTables = getSystemTables();
	if (in_array($tabel, $systemTables)) { die(); }
	if (isset($_GET["selected"])) {
		$selected = htmlspecialchars($_GET["selected"], ENT_QUOTES);
	}
	else {
		if (!$query = mysql_query("SELECT id FROM ".$tabel." ORDER BY andmebaasi_lisatud DESC LIMIT 1")) { die(); }
		$query = mysql_fetch_array($query);
		$selected = $query["id"];
	}
	$xtabel = htmlspecialchars($_GET["u"], ENT_QUOTES);
	$shows = get_must_show_columns($tabel);
	$kysi_teisest_tabelist = mysql_query("SELECT * FROM ".$tabel." ORDER BY ".$shows[0]);
	if ($_GET["materjal"] == "roll" or $_GET["materjal"] == "digitaliseerija") {
		$tabel = "materjal_id";
	}
	if (!$xtabel) {
		$xtabel = $_GET["materjal"];
	}
	echo "<select name='".$tabel."' width='300' style='width: 300px' onchange=\"arhiiviNr('".$xtabel."', this.value); ab('".$xtabel."');\"><option value=''></option>";
	while ($rida = mysql_fetch_array($kysi_teisest_tabelist)) {
		if ($rida["id"] == $selected) { $sel = " selected='selected'"; } else { $sel = ""; }
		echo "<option value='".$rida["id"]."'".$sel.">";
		foreach ($shows as $show) { echo " ".$rida[$show]; }
		echo "</option>";
	}
	echo "</select>";
}
?>